#include <cstdio>
#include <cstring>

#define eps 1e-8

int d[ 1 << 15 ][ 16 ], f[ 1 << 15 ], s[ 1 << 15 ], n, m;

void init( )
{
    int i, j, k, t;
    memset( d, 0x7f, sizeof( d ) );
    memset( s, 0, sizeof( s ) );
    for ( i = 0; i < n; i++ )
    {
        scanf("%d", &t);
        for ( j = 0; j < ( 1 << n ); j++ )
            if ( j & ( 1 << i ) )
                s[ j ] += t;
    }
    for ( i = 0; i < n; i++ )
        for ( j = 0; j < n; j++ )
        {
            scanf("%d", &t);
            for ( k = 0; k < ( 1 << n ); k++ )
                if ( ( k & ( 1 << i ) ) && !( k & ( 1 << j ) ) && d[ k ][ j ] > t )
                    d[ k ][ j ] = t;
        }
    for ( i = 0; i < ( 1 << n ); i++ )
        f[ i ] = -1;
    for ( i = 0; i < n; i++ )
        f[ 1 << i ] = 0;
}

int find( int p )
{
    int i, t, minn;
    if ( f[ p ] != -1 )
        return f[ p ];
    minn = 0xfffffff;
    for ( i = 0; i < n; i++ )
        if ( ( 1 << i ) & p )
        {
            t = find( ( 1 << i ) ^ p );
            if ( minn > t + d[ ( 1 << i ) ^ p ][ i ] )
                minn = t + d[ ( 1 << i ) ^ p ][ i ];
        }
    return f[ p ] = minn;
}

int countdigit( int x )
{
    int t = 0;
    while ( x )
    {
        t += x & 1;
        x >>= 1;
    }
    return t;
}

void work( )
{
    int i, t, minn;
    double minratio = 10000000;
    bool first = true;
    for ( i = 1; i < ( 1 << n ); i++ )
    {
        if ( countdigit( i ) != m )
            continue;
        if ( minratio > double( f[ i ] ) / s[ i ] + eps )
        {
            minratio = double( f[ i ] ) / s[ i ];
            minn = i;
        }
    }
    for ( i = 0; i < n; i++ )
        if ( ( 1 << i ) & minn )
            if ( first )
            {
                printf("%d", i + 1);
                first = false;
            }
            else
                printf(" %d", i + 1);
    printf("\n");    
}

int main( )
{
    while ( scanf("%d%d", &n, &m) )
    {
        if ( n == 0 && m == 0 )
            break;
        init( );
        find( ( 1 << n ) - 1 );
        work( );
    }
    return 0;
}